<template>
    <div>
        <Table border :columns="columns" :data="tableData">
            <template slot-scope="{ row }" slot="action">
                <div class="action-button">
                    <Button v-if="row.dept_audit_status==='draft'" type="primary" size="small"  @click="goEdit(row.id)">编辑</Button>
                    <Button v-if="row.dept_audit_status==='draft'" type="error" size="small" @click="deleteDataModal(row.id)">删除</Button>
                    <Button type="success" size="small" @click="goDetail(row.id)">详情</Button>
                </div>
            </template>
        </Table>
        <Page :total="pageInfo.total" :current="pageInfo.pageNo" @on-change="changePage" />
        <Modal v-model="deleteModal" title="确认操作" width="20" @on-ok="deleteData" >
            <div style="text-align:center">
                <p>是否确认删除!</p>
            </div>
        </Modal>

    </div>
</template>
<script>
import { findPageList, deleteRequest } from '@/api/outbreak-management/outbreak-surveillance/case-trend'
// 街道疫情
export default {
  data () {
    return {
      // 弹出框
      deleteModal: false,
      // 删除 id
      currentDelId: '',
      // 表格
      columns: [
        {
          title: '上报日期',
          key: 'imp_date',
          minWidth: 120,
          render: (h, params) => {
            let date = this.$common.moment(params.row.imp_date).format('YYYY-MM-DD')
            return h('div', date)
          }
        },
        {
          title: '确诊病例数',
          minWidth: 120,
          key: 'diagnose_num'
        },
        {
          title: '疑似病例数',
          minWidth: 80,
          key: 'suspected_num'
        },
        {
          title: '审核状态',
          minWidth: 120,
          key: 'dept_audit_status',
          render: (h, params) => {
            let date = '未知状态'
            let dept_audit_status = params.row.dept_audit_status
            let leader_audit_status = params.row.leader_audit_status
            if (dept_audit_status === 'draft') {
              date = '未提报'
            } else if (dept_audit_status === 'commit') {
              date = '部门已审核'
            } else if (dept_audit_status === 'audited' && leader_audit_status === 'unaudited') {
              date = '分项已审核'
            } else if (dept_audit_status === 'audited' && leader_audit_status === 'audited') {
              date = '区已审核'
            }
            return h('div', date)
          }
        },
        {
          title: '操作',
          slot: 'action',
          fixed: 'right',
          width: 180,
          align: 'center'
        }
      ],
      tableData: [],
      pageInfo: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  mounted () {
    this.changePage(this.pageInfo.pageNo)
  },
  methods: {
    // 详情
    goDetail (id) {
      this.$router.push({ name: 'case-trend-add', query: { id: id, showDetail: true } })
    },
    // 修改
    goEdit (id) {
      this.$router.push({ name: 'case-trend-add', query: { id: id } })
    },
    // 删除
    deleteDataModal (id) {
      this.currentDelId = id
      this.deleteModal = true
    },
    deleteData () {
      deleteRequest({ id: this.currentDelId }).then(({ data }) => {
        let { errcode } = data
        if (errcode === 0) {
          this.$Message.success('删除成功!')
          this.currentDelId = ''
          this.getTableData()
        } else {
          this.$Message.warning('删除失败!')
        }
      })
    },
    // 分页查询查找
    getTableData () {
      findPageList(this.pageInfo).then(({ data }) => {
        let { errcode, data: res } = data
        if (errcode === 0) {
          this.tableData = res.results
          this.pageInfo.total = res.totalRecord
        } else {
          this.$Message.warning('获取信息失败!')
        }
      })
    },
    // 分页
    changePage (pageNo) {
      this.pageInfo.pageNo = pageNo
      this.getTableData()
    }
  }
}
</script>

<style scoped lang="less">

</style>
